import {request} from '@/api/request/index.js'

let classifylist=[]
let resultList=[]
function getClassifyList(list){
	list.sort((a,b)=>{return a.ID-b.ID})
	//获取分类名称
	list.map((item,idx)=>{
		let classifyname=item.Brand
		if(classifylist.indexOf(classifyname)<=-1) classifylist.push(classifyname)
	})
	//结合体
	classifylist.map(classifyname=>{
		let r =[],r1={}
		list.map((item,idx)=>{
			if(classifyname == item.Brand){
				r.push(item)
			}
		})
		r1 = {classifyName:classifyname,List:r},
		resultList.push(r1)
	})
	
	return {c1:classifylist,c2:resultList}
}

export default {
	getProlist(callback) {
		uni.showLoading({
			mask:true,
			title:'正在加载模块...'
		})
		request.get({
				data: {
					c: 'NsCakeCenter',
					m: 'GetJdListNew'
				}
			})
			.then(res => {
				let cakelist =[],tag={};
				if (res.Status == "ok") {
					cakelist = res.Tag.cakelist;
					tag=getClassifyList(cakelist)
				}
				if(callback) callback(tag)
			})
			.catch(error => {
				if(callback) callback({})
			});
	}
}
